package com.huifai.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import javax.sql.DataSource;

/**
 * <br>==========================
 * <br> 开发：jerry
 * <br> 创建时间：2019-05-30 下午2:43
 * <br> 版本：1.0
 * <br> 描述：动态数据库连接配置类,为扩展多数据源准备
 * <br>==========================
 */
@Configuration
@EnableTransactionManagement(proxyTargetClass = true)
public class DynamicDataSource {

	@Autowired
	private DruidDataSourceConfig druidDataSourceConfig;

	@Bean
	public DataSource dataSource(){
		DataSource dataSource = druidDataSourceConfig.targetDataSource();
		return dataSource;
	}

	@Bean
	public PlatformTransactionManager transactionManager(){
		return new DataSourceTransactionManager(dataSource());
	}

}
